import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/*
 * @(#)sendMail.java
 *
 * Copyright 2011 Xinhua Online, Inc. All rights reserved.
 */

/**
 * description
 * 
 * @author huangyixiang
 * @version 2011-11-1
 */
public class sendMail {
	public static void main(String[] args) {
		// 测试成功
		Properties props = new Properties();
		props.setProperty("mail.smtp.auth", "true");
		props.setProperty("mail.transport.protocol", "smtp");
		Session session = Session.getInstance(props);
		session.setDebug(true);
		Message msg = new MimeMessage(session);
		try {
			// msg.setText("你好");
			// 发送的邮箱地址
			msg.setFrom(new InternetAddress("43385607@qq.com"));
			msg.setSubject("hello");
			msg.setContent("<span style='color:red'>hehe</span>我爱你",
					"text/html;charset=gbk;");
			Transport transport = session.getTransport();
			// 设置服务器以及账号和密码
			transport.connect("smtp.qq.com", 25, "43385607", "xxxxxxxxxxxxxxxxxx");
			// 发送到的邮箱地址
			transport.sendMessage(msg, new Address[] { new InternetAddress(
					"43385607@qq.com") });
			transport.close();
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
